package com.example.demo.controller;

import com.example.demo.DTO.DeviceDTO;
import com.example.demo.VO.ResultVO;
import com.example.demo.dataobject.Device;
import com.example.demo.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/device")
public class DeviceController {
    @Autowired
    DeviceService deviceService;

    @GetMapping("/list")
    public ResultVO list(Integer id){
        Device result = deviceService.findOne(id);

        ResultVO resultVO = new ResultVO();
        resultVO.setData(new ArrayList());
        resultVO.getData().add(result);
        return resultVO;
    }

    @GetMapping("/findwith")
    @ResponseBody
    public ResultVO findwith(Integer id){
        DeviceDTO result = deviceService.findwith(id);

        ResultVO list = new ResultVO();
        list.setCode(200);
        list.setMsg("成功");
        list.setDatas(result);
        return list;
    }
}
